package com.lzb.permanentcalendar.activity;

import android.graphics.Color;
import android.view.View;

import androidx.fragment.app.Fragment;

import com.blankj.utilcode.util.FragmentUtils;
import com.lzb.permanentcalendar.BaseAc;
import com.lzb.permanentcalendar.R;
import com.lzb.permanentcalendar.databinding.ActivityDateConversionBinding;
import com.lzb.permanentcalendar.fragment.DateCalculationFragment;
import com.lzb.permanentcalendar.fragment.DateIntervalFragment;
import com.lzb.permanentcalendar.fragment.DateSwapFragment;

import java.util.ArrayList;
import java.util.List;

public class DateConversionActivity extends BaseAc<ActivityDateConversionBinding> implements View.OnClickListener {

    private List<Fragment> mFragmentList;


    @Override
    protected int onCreate() {
        return R.layout.activity_date_conversion;
    }

    @Override
    protected void initView() {
        mDataBinding.llDateSwap.setOnClickListener(this);
        mDataBinding.llDateInterval.setOnClickListener(this);
        mDataBinding.llDateCalculation.setOnClickListener(this);

        mFragmentList = new ArrayList<>();
        mFragmentList.add(new DateSwapFragment());
        mFragmentList.add(new DateIntervalFragment());
        mFragmentList.add(new DateCalculationFragment());
        FragmentUtils.add(getSupportFragmentManager(), mFragmentList, R.id.flContainer, 0);
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.llDateSwap) {//日期互换
            clearSelection();
            mDataBinding.tvDateSwap.setTextColor(Color.parseColor("#AD2419"));
            mDataBinding.ivDateSwap.setVisibility(View.VISIBLE);
            FragmentUtils.showHide(0, mFragmentList);
        } else if (id == R.id.llDateInterval) {//日期间隔
            clearSelection();
            mDataBinding.tvDateInterval.setTextColor(Color.parseColor("#AD2419"));
            mDataBinding.ivDateInterval.setVisibility(View.VISIBLE);
            FragmentUtils.showHide(1, mFragmentList);
        } else if (id == R.id.llDateCalculation) {//日期推算
            clearSelection();
            mDataBinding.tvDateCalculation.setTextColor(Color.parseColor("#AD2419"));
            mDataBinding.ivDateCalculation.setVisibility(View.VISIBLE);
            FragmentUtils.showHide(2, mFragmentList);
        }
    }

    @Override
    protected void initData() {

    }

    private void clearSelection() {
        mDataBinding.tvDateSwap.setTextColor(Color.parseColor("#999999"));
        mDataBinding.ivDateSwap.setVisibility(View.GONE);
        mDataBinding.tvDateInterval.setTextColor(Color.parseColor("#999999"));
        mDataBinding.ivDateInterval.setVisibility(View.GONE);
        mDataBinding.tvDateCalculation.setTextColor(Color.parseColor("#999999"));
        mDataBinding.ivDateCalculation.setVisibility(View.GONE);
    }
}